<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">

	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form test_edit" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">

							<div class="layui-card">
								<div class="layui-card-body">
									<div class="layui-form-item">
										<label class="layui-form-label">状态：</label>
										<div class="layui-input-block">
											<input type="radio" name="status" value="-1" title="拒绝">
											<!--<input type="radio" name="status" value="0" title="待审核">-->
											<input type="radio" name="status" value="1" title="通过" checked="">
										</div>
									</div>
								</div>
							</div>



							<div style="display: flex;">

								<div class="layui-form-item">
									<label class="layui-form-label">姓名1：</label>
									<div class="layui-input-block">
										<input type="text" name="name" placeholder="请输入姓名" autocomplete="off"
											class="layui-input">
									</div>
								</div>

								<div class="layui-form-item">
									<label class="layui-form-label">性别：</label>
									<div class="layui-input-block sex"></div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">商户名称：</label>
									<div class="layui-input-block">
										<input type="text" name="shop_name" placeholder="请输入站点名称" autocomplete="off"
											class="layui-input">
									</div>
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">手机号码：</label>
								<div class="layui-input-block">
									<input type="text" name="mobile" lay-verify="required" placeholder="请输入手机号码"
										autocomplete="off" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">紧急电话：</label>
								<div class="layui-input-block">
									<input type="text" name="phone" lay-verify="required" placeholder="请输入紧急电话"
										autocomplete="off" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">小区名称：</label>
								<div class="layui-input-block">
									<input type="text" name="area" placeholder="请输入小区名称" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">详细地址：</label>
								<div class="layui-input-block">
									<input type="text" name="address" placeholder="请输入个人备注" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">备注：</label>
								<div class="layui-input-block">
									<input type="text" name="remark" placeholder="请输入备注" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">原因：</label>
								<div class="layui-input-block">
									<input type="text" name="cause" placeholder="请输入原因" autocomplete="off"
										class="layui-input">
								</div>
							</div>

							<div class="layui-form-item upvideo">
								<label class="layui-form-label">营业执照</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(1)">上传文件</button>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										<ul class="show_img_ul" id="license_pic"></ul>
									</blockquote>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">门头照</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(2)">上传文件</button>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										<ul class="show_img_ul" id="shop_front_pic"></ul>
									</blockquote>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">店内照</label>
								<div class="layui-input-block">

									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(4)">上传图片</button>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										<ul class="show_img_ul" id="shop_inb_pic"></ul>
									</blockquote>
								</div>
							</div>



							<div class="layui-form-item">
								<label class="layui-form-label">位置：</label>
								<div class="layui-input-block">
									<div id="map-container" style="height: 500px; border: 1px solid #d6ccd6;"></div>
								</div>
							</div>

							<!-- 		<div class="layui-form-item">
								<label class = "layui-form-label">评星等级：</label>
								<div id = "score"></div>
							</div> -->

							<!--<div class="layui-form-item">
								<label class="layui-form-label">是否推荐：</label>
								<div class="layui-input-block">
									<input type="checkbox" name="status" lay-skin="switch" lay-text="推荐|不推荐">
								</div>
							</div>
							-->
							<!-- 		<div class="layui-form-item">
								<label class="layui-form-label">服务类型：</label>
								<div class="layui-input-block service_type"></div>
							</div> -->

						</div>
					</div>

					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script src="https://webapi.amap.com/maps?v=1.4.15&key=2d30eff9da600d78fba843b033c4eecd"></script>
		<script>
			var positions; //获取接口的坐标
			var coordArr; //把接口的坐标转成数组
			var numArr; //把数组中的坐标转换成数字
			var marker; // 定义全局变量保存标记点对象
			var shopStation; //获取到店铺信息
			var setPosition; //修改位置的信息


			//用来显示地图的函数
			function showMap() {
				// console.log("接口坐标", numArr);
				// 初始化地图对象
				var map = new AMap.Map('map-container', {
					zoom: 12,
					center: numArr
				});
				// 创建标记并添加到地图上
				var marker = new AMap.Marker({
					position: numArr,
					map: map,
					draggable: true,
					icon: new AMap.Icon({
						size: new AMap.Size(35, 35),
						image: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png',
						offset: new AMap.Pixel(-12, -24)
					}),
					cursor: 'move'
				});
				// 显示标记信息窗口
				showInfoWindow(marker, map, true); //调用弹出信息窗口函数
				// 监听标记的拖动事件
				marker.on('dragend', function(event) {
					// 当标记结束拖动后，记录新的坐标信息
					console.log('拖动后的坐标：' + event.lnglat.getLng() + ',' + event.lnglat.getLat());
					setPosition = event.lnglat.getLng() + ',' + event.lnglat.getLat()
					// 在标记旁边显示店铺信息和坐标信息
					showInfoWindow(marker, map, false); //调用弹出信息窗口函数
				});
			}

			function showInfoWindow(marker, map, isOpen) {
				// 在标记旁边显示店铺信息和坐标信息
				var setLnglat = marker.getPosition().getLng() + ',' + marker.getPosition().getLat();
				var content = '<div class="infoWindow" >' +
					'<p>店铺信息：' + shopStation + '</p>' +
					'<p>坐标信息：' + setLnglat + '</p>' +
					'</div>';
				var infoWindow = new AMap.InfoWindow({
					offset: new AMap.Pixel(0, -30),
					content: content,
					closeButton: false //关闭小叉号
				});
				if (isOpen) {
					// 是否默认打开信息窗口
					infoWindow.open(map, marker.getPosition());
				} else {
					infoWindow.open(map, marker.getPosition());
				}
			}



			var _data = {
				id: getParam('id'),
			}
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit', 'rate', 'upload'], function() {
				var $ = layui.$,
					admin = layui.admin,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					upload = layui.upload,
					form = layui.form;
				var rate = layui.rate;
				var img_arr3 = [],
					img_arr1 = [],
					img_arr10 = [],
					img_arr2 = []
				img_arr4 = []
				//渲染
				var ins1 = rate.render({
					elem: '#score', //绑定元素
					half: true,
					value: _data.score,
					choose: function(value) {
						_data.score = value;
					}
				});

				sex_show('radio');

				service_type_show('checkbox');





				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					_data.shop_front_pic = img_arr2.join(',');
					_data.shop_inb_pic = img_arr4.join(',');
					_data.license_pic = img_arr1.join(',');
					var lock = false;
					_data.positions = setPosition;
					var input_value1 = $("#value1").val;
					$("#business_img").attr("src", input_value1)
					console.log("看看所有的表单数据", _data);

					var lock = false
					layer.confirm('确定要提交数据？', function() {
						if (!lock) {
							lock = true
							loading();
							if (_data.id) {
								submitdata(server.sys_shop_car_check);
							}
							// else {
							// 	delete _data.id;
							// 	submitdata(server.master_insert);
							// }
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function submitdata(_url) {

					$.post(_url, _data, function(res, status) {
						console.log("看看提交的数据", _url, _data);
						if (status == 'success') {
							if (res.code == 0) {
								console.log("修改成功后的", res);
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				};
				initdata();

				function initdata() {
					$.get(server.sys_shop_sub_detail, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								console.log(res)
								var data = res.shop_sub
								// 获取 positions 坐标的数据
								if(res.shop_sub.data.positions){
									positions = res.shop_sub.data.positions;
									coordArr = positions.split(",");
									numArr = [parseFloat(coordArr[0]), parseFloat(coordArr[1])];
								}
								shopStation = res.shop_sub.data.shop_name;
								// _data.shop_front_pic = img_arr2.join(',');
								// _data.shop_inb_pic = img_arr4.join(',');
								// _data.license_pic = img_arr1.join(',');

								data.data.shop_front_pic ? createli(data.data.shop_front_pic, 'shop_front_pic','2') : ''
								data.data.shop_inb_pic ? createli(data.data.shop_inb_pic, 'shop_inb_pic', '4') : ''
								data.data.license_pic ? createli(data.data.license_pic, 'license_pic', '1') : ''

								// v-html(red.shop_sub.data.img)

								if (numArr != undefined) {
									showMap()
								}

								var data = res.shop_sub
								form.val("test_detail", data.data);


								// var unitType = [];
								// unitType = data.data.type.split(",");
								// var unitTypeCheckbox = $(".service_type").children('input');

								// for (var j = 0; j < unitType.length; j++) {
								// 	for (var i = 0; i < unitTypeCheckbox.length; i++) {
								// 		if (unitTypeCheckbox[i].value == unitType[j]) {
								// 			unitTypeCheckbox[i].checked = true;
								// 		}
								// 	}
								// }



								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}





				window.choose = function(data) {
					layer.open({
						type: 2,
						title: '上传图片',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['700px', '400px'],
						content: '../../model/up_report.html?type=' + data,
						end: function() {},
						success: function() {}
					});
				}
				window.getimg = function(data, type) { //当单击确定data是图片上传服务器后的地址 type是数字类型
					if (data) {
						switch (type) {
							case '1':
								createli(data, 'license_pic', type)
								break;
							case '2':
								createli(data, 'shop_front_pic', type)
								break;
							case '4':
								createli(data, 'shop_inb_pic', type)
								break;
							default:
								break;
						}
					}
				}
				window.delimg = function(i, type, _self) {
					var _type = String(type)
					var lock = false
					layer.confirm('确定要删除图片？', function(index) {
						if (!lock) {
							lock = true
							switch (_type) {
								case '1':
									img_arr1.splice(i, 1)
									break;
								case '2':
									img_arr2.splice(i, 2)
									break;
								case '4':
									img_arr4.splice(i, 4)
									break;
								default:
									break;
							}
							$(_self).parent().remove();
							layer.close(index)
						}
					}, function() {
						layer.msg('取消操作');
					});
				}

				function createli(data, dom, type) { //当单击确定data是图片上传服务器后的地址 type是数字类型
					console.log("执行顺序3", data, "+", dom, type);
					console.log(data)
					var lihtml = '';
					switch (type) {
						case '1':
							if (data.indexOf(',') == -1) {
								img_arr1.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr1.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr1.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr1[i] + ' >' +
									'<p onclick="delimg(' + i + ',4,this)">删除</p>' +
									'</li>'
							}
							break;
						case '2':
							if (data.indexOf(',') == -1) {
								img_arr2.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr2.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr2.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr2[i] + ' >' +
									'<p onclick="delimg(' + i + ',2,this)">删除</p>' +
									'</li>'
							}
							break;
						case '4':
							if (data.indexOf(',') == -1) {
								img_arr4.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr4.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr4.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr4[i] + ' >' +
									'<p onclick="delimg(' + i + ',4,this)">删除</p>' +
									'</li>'
							}
							break;
						default:
							break;
					}
					$('#' + dom).html(lihtml);
				}



			});
		</script>
	</body>

</html>